/*
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 *
 * This file is part of Harmattan SmashMiner OpenGL game application.
 * 
 * Harmattan SmashMiner OpenGL Example Application version 1.0.0
 *  
 * Latest update: 15.4.2011
 *
 * The Harmattan SmashMiner OpenGL example application demonstrates how to use 
 * the OpenGL ES in Harmattan devices.
 *
 * This example is provided as a starting point for 3rd party
 * developers (you) to ease the implementation of OpenGL based 
 * games. Ideas, parts of code or methodologies that this
 * example application uses can be freely used without restrictions.
 *
 * See file README.txt how to build and compile this example application
 * in the Harmattan SDK environment. 
 * 
 * See file INSTALL.txt to find out what is required to run this
 * application and how to install the application to the device or
 * alternatively in QEMU-emulator.
 *
 * The LICENSE.txt file explains the license this software is provided
 * with. A copy of the same license is included in this source file.
 * 
 */

/*
 * Copyright (C) 2011 by Nokia Corporation.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#include "rotatingobject.h"
#include "gameengine.h"

/*! \class RotatingObject
   Game object that is rotating when moving on screen.
*/

/// Constructor
RotatingObject::RotatingObject() 
    : rotation_angle(0.0)
    , rotation_speed(0.2)
    , rotation_angleStart(0.0)
{
    rotation_axis[0] = 0.0;
    rotation_axis[1] = 1.0;
    rotation_axis[2] = 0.0; // to swirl set to 0.1
    GameEngine::normalizeVect3D_GLfloat(rotation_axis);
}

/// Integrates current rotation angle for the \a timestep
void RotatingObject::integrateRotation(FPtype timestep)
{
    rotation_angle += rotation_speed * timestep;
    if (rotation_angle < 0.0f) rotation_angle += 360.0f;
    if (rotation_angle > 360.0f) rotation_angle -= 360.0f;
}

/// Sets rotation angle
void RotatingObject::setRotationAngle(GLfloat angle)
{
    rotation_angle = angle;
    rotation_angleStart = angle;
}

/// Sets rotation speed
void RotatingObject::setRotationSpeed(GLfloat speed)
{
    rotation_speed = speed;
}

/// Sets rotation value for axis. X axle is \a first. Y axle is \a second. Z axle is \a third.
void RotatingObject::setRotationAxis(GLfloat first,GLfloat second,GLfloat third)
{
    rotation_axis[0] = first;
    rotation_axis[1] = second;
    rotation_axis[2] = third;
}

/// Sets rotation value for axis given at \a index. X axle is 0. Y axle 1. Z axle is 2.
void RotatingObject::setRotationAxis(int index,GLfloat value)
{
    if (index <= 2)
        rotation_axis[index] = value;
}
